//
//  ViewController.m
//  汤姆猫
//
//  Created by student on 16/2/20.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#import "TomModel.h"

#define kOnePictureSpeed 0.05
@interface ViewController ()

@property (nonatomic,strong) TomModel *tomModel;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;


@end

@implementation ViewController
//懒加载数据
-(TomModel *)tomModel{
    if (_tomModel == nil) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"tom.plist" ofType:nil];
        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
        _tomModel = [TomModel tomModelWithDict:dic];
    }
    return _tomModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
//drink动画
- (IBAction)didClickDrinkBtn{
    NSString *name = @"drink_";
    [self playAnimatingWithCount:self.tomModel.drink WithPicName:name];
}
//
- (IBAction)didClickCymbalBtn {
    NSString *name = @"cymbal_";
    [self playAnimatingWithCount:self.tomModel.cymbal WithPicName:name];
}
- (IBAction)didClickEatBtn {
    NSString *name = @"eat_";
    [self playAnimatingWithCount:self.tomModel.eat WithPicName:name];
}
- (IBAction)didClickPieBtn {
    NSString *name = @"pie_";
    [self playAnimatingWithCount:self.tomModel.pie WithPicName:name];
}
- (IBAction)didClickScratchBtn {
    NSString *name = @"scratch_";
    [self playAnimatingWithCount:self.tomModel.scratch WithPicName:name];
}
- (IBAction)didClickFartBtn {
    NSString *name = @"fart_";
    [self playAnimatingWithCount:self.tomModel.fart WithPicName:name];
}
- (IBAction)didClickLeftFootBtn {
    NSString *name = @"footLeft_";
    [self playAnimatingWithCount:self.tomModel.foot_left WithPicName:name];
}
- (IBAction)didClickRightFootBtn {
    NSString *name = @"footRight_";
    [self playAnimatingWithCount:self.tomModel.foot_right WithPicName:name];

}
- (IBAction)didClickKnockBtn{
    NSString *name = @"knockout_";
    [self playAnimatingWithCount:self.tomModel.knockout WithPicName:name];

}
- (IBAction)didClickStomachBtn {
    NSString *name = @"stomach_";
    [self playAnimatingWithCount:self.tomModel.stomach WithPicName:name];
}

-(void)playAnimatingWithCount:(int)picCount
                  WithPicName:(NSString *)name{
    NSMutableArray *mutArr = [NSMutableArray array];
    for (int i=0; i<picCount; i++) {
        NSString *picName = [NSString stringWithFormat:@"%@%02d",name,i];
        UIImage *image = [UIImage imageNamed:picName];
        [mutArr addObject:image];
    }
    self.imageView.animationImages = mutArr;
    self.imageView.animationDuration = picCount*kOnePictureSpeed;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
